import java.util.Scanner;
public class Average{
  // Finds the average of a number of grades
  public static void main(String[] args){
    int count = 0;
    double grade, sumOfGrades = 0.0;
    Scanner scanner = new Scanner(System.in);

    System.out.printf("Enter grade#%d ( 0 < or > 100 to terminate): ", count+1);
    grade = scanner.nextDouble();
    while(grade >= 0 && grade <= 100){
       count++;
       sumOfGrades += grade;
       System.out.printf("Enter grade#%d ( 0 < or > 100 to terminate): ", count+1);
       grade = scanner.nextDouble();
    }
    if(count == 0)
      System.out.println("Error: No valid grade entered");
    else
       System.out.printf("Average = %.2f\n", sumOfGrades / count);
  }
}
